package patterns;

public final class BadInstanceof {

	  public static void doSomething(Animal aAnimal){
	    if (aAnimal instanceof Fish){
	      Fish fish = (Fish)aAnimal;
	      fish.swim();
	    }
	    else if (aAnimal instanceof Spider){
	      Spider spider = (Spider)aAnimal;
	      spider.crawl();
	    }
	  }

	  // PRIVATE //
	  private static class Animal {}

	  private static final class Fish extends Animal {
	    void swim(){System.out.println("swim");}
	  }
	  private static final class Spider extends Animal {
	    void crawl(){System.out.println("crawl");}
	  }
	  
	  public static void main(String[] args) {
		  doSomething(new Fish());
		  doSomething(new Spider());
	  }
} 
